﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Template/Site_Main.Master" AutoEventWireup="true"
    CodeBehind="notice_manage.aspx.cs" Inherits="RegisterationSystem.Space_Education.notice_manage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
      <!--
        $(function () {
            //设置导航位置
            setLocalToParent(1);
            var products = [
		    { id: '0', name: '全部' },
		    { id: '1', name: '学校' },
		    { id: '2', name: '家长' },
            { id: '3', name: '被放弃学生' }
		    ];
            //初始化隐藏层
            $('#plastudentinfo').dialog({
                closed: true
            });
            //初始化企业用户数据列表控件
            $("#dg").datagrid({
                idField: "id",      //标识字段,主键
                url: "../SyncService/GetDataList.ashx?action=getnoticelist",
                queryParams: { "where": "1=1" },
                pagination: true,   //是否开启分页
                rownumbers: true,   //行号
                pageSize: 10,
                pageNumber: 1,
                columns: [[
                            { field: 'ck', checkbox: true },
                            
                            { field: 'tile', title: '公告标题', width: 200, align: 'center' },
                            { field: 'recrive', title: '接收对象 ', width: 120, align: 'center',
                                formatter: function (value) {
                                    for (var i = 0; i < products.length; i++) {
                                        if (products[i].id == value) return products[i].name;
                                    }
                                    return "请选择接收对象";
                                },
                                editor: { type: 'combobox', options: { valueField: 'id',
                                    textField: 'name',
                                    data: products,
                                    required: true
                                }
                                }
                            },
                            { field: 'status', title: '公告状态', width: 100, align: 'center', formatter: function (value, row) {
                                if (value) {
                                    return "不显示";
                                } else {
                                    return "显示";
                                }
                            }
                        },
                        { field: 'time', title: '公告时间', width: 200, align: 'center' },
                            { field: 'id', title: '查看详细信息', width: 250, align: 'center', formatter: function (value, row) {
                                return "<a href='javascript:void(0)' onclick='GetByStudentInfo(" + value + ");' >查看详细信息</a>";
                            }
                            }
                         ]],
                onClickRow: function (index, row) {
                    if (editIndex != index) {
                        if (endEditing()) {
                            $('#dg').datagrid('beginEdit', index);
                            editIndex = index;
                        } else {
                            $('#dg').datagrid('selectRow', editIndex);
                        }
                    }
                }
            })
        });
        //-->
        //选择下一行的时候，修改前行
        var editIndex = undefined;
        function endEditing() {
            if (editIndex == undefined) { return true }
            if ($('#dg').datagrid('validateRow', editIndex)) {
                var ed = $('#dg').datagrid('getEditor', { index: editIndex, field: 'id' });
                //var productname = $(ed.target).combobox('getText');
                //$('#tt').datagrid('getRows')[editIndex]['productname'] = productname;
                $('#dg').datagrid('endEdit', editIndex);
                editIndex = undefined;
                return true;
            } else {
                return false;
            }
        }

        //批量选择(修改)
        function Getcheckbox() {
            //修改未编辑完的行
            $('#dg').datagrid('endEdit', editIndex);
            //id集合
            var ids = "";
            //接收对象集合
            var counts = "";
            //获取选择集合
            var rows = $('#dg').datagrid('getSelections');
            //是否选中行
            if (rows.length == 0) {
                alert("请选择行");
                return;
            }
            //遍历选择行
            for (var i = 0; i < rows.length; i++) {
                if (rows[i].recrive != undefined) {
                    ids += rows[i].id + ",";
                    counts += rows[i].recrive + ",";
                }
            }
            //是否选择学校
            if (counts.length == 0) {
                alert("请选择接收对象");
                return;
            }
            $.messager.confirm('提示', '确认修改接受对象？', function (r) {
                if (r) {
                    $.post(location.href, { "action": "upd", "id": ids, "count": counts }, function (data) {
                        $.messager.alert("消息提示", "修改成功！");
                        $('#dg').datagrid('reload');
                    });
                }
            });
        }

        //修改状态
        function updstatus(sid) {
            //修改未编辑完的行
            $('#dg').datagrid('endEdit', editIndex);
            //id集合
            var ids = "";
            //获取选择集合
            var rows = $('#dg').datagrid('getSelections');
            //是否选中行
            if (rows.length == 0) {
                alert("请选择行");
                return;
            }
            //遍历选择行
            for (var i = 0; i < rows.length; i++) {
                ids += rows[i].id + ",";
            }
            $.messager.confirm('提示', '确认修改公告状态？', function (r) {
                if (r) {
                    $.post(location.href, { "action": "updstatus", "id": ids, "sid": sid }, function (data) {
                        $.messager.alert("消息提示", "修改成功！");
                        $('#dg').datagrid('reload');
                    });
                }
            });
        }

        //删除
        function del() {
            //修改未编辑完的行
            $('#dg').datagrid('endEdit', editIndex);
            //id集合
            var ids = "";
            //获取选择集合
            var rows = $('#dg').datagrid('getSelections');
            //是否选中行
            if (rows.length == 0) {
                alert("请选择行");
                return;
            }
            //遍历选择行
            for (var i = 0; i < rows.length; i++) {
                ids += rows[i].id + ",";
            }
            $.messager.confirm('提示', '确认删除公告？', function (r) {
                if (r) {
                    $.post(location.href, { "action": "del", "id": ids }, function (data) {
                        $.messager.alert("消息提示", "删除成功！");
                        $('#dg').datagrid('reload');
                    });
                }
            });
        }

        //弹出公告详细信息
        function GetByStudentInfo(stdID) {
            $("#<%= hidstuID.ClientID %>").val(stdID);
            $.post("../SyncService/GetDataList.ashx",
                { "action": "GetNoticeByID", "id": stdID },
                function (cStr) {
                    var stdInfo = eval('(' + cStr + ')');
                    $("#txttilt").val(stdInfo.tile); //标题
                    $("#txtcount").val(stdInfo.content); //内容
                    $('#selsta').combobox('setValues', stdInfo.status);
                    $('#selrec').combobox('setValues', stdInfo.recrive);
                },
                "text");
            //弹层
            $('#plastudentinfo').dialog({
                title: '公告信息',
                width: 600,
                height: 360,
                closed: false,
                cache: false,
                modal: true,
                collapsible: true,
                maximizable: false
            });
        }

        //修改公告信息
        function updatenoice() {
            var id = $("#<%= hidstuID.ClientID %>").val();
            var tile = $("#txttilt").val(); //标题
            var count = $("#txtcount").val(); //内容
            var status = $('#selsta').combobox("getValue");
            var rec = $('#selrec').combobox("getValue");
            $.messager.confirm('提示', "是否确认修改？", function (r) {
                if (r) {
                    $.post(location.href, { "action": "updnotice", "id": id, "status": status, "tile": tile, "count": count, "rec": rec }, function (data) {
                        $.messager.alert("消息提示", "修改成功!");
                        //关闭
                        $("#plastudentinfo").dialog("close");
                        $('#dg').datagrid('reload');
                    });
                }
            });
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Place_Local" runat="server">
    <div class="localTitle">
        <a>公告列表管理</a>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <!--选择的公告信息编号-->
    <asp:HiddenField ID="hidstuID" runat="server" />
    <div class="loadheight">
        <table width="100%%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td bgcolor="#FFFFFF">
                    <table width="100%%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td>
                                <table width="100%" border="0" cellpadding="0" cellspacing="0">
                                </table>
                            </td>
                        </tr>
                    </table>
                    <table width="100%%" border="0" cellspacing="0" cellpadding="1">
                        <tr>
                            <td class="cen_R_dh">
                                <strong>公告列表管理</strong>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <!-- 创建数据列表控件 -->
                                <table id="dg">
                                </table>
                                <div style="margin-top: 10px;">
                                </div>
                                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                    <tr>
                                        <td align="left">
                                            <input type="button" name="button2" id="button4" value="修改" class="anniu" width="73px"
                                                height="23px" onclick="Getcheckbox();" />
                                            <input type="button" name="button2" id="button1" value="显示" class="anniu" width="73px"
                                                height="23px" onclick="updstatus(0);" />
                                            <input type="button" name="button2" id="button3" value="不显示" class="anniu" width="73px"
                                                height="23px" onclick="updstatus(1);" />
                                            <input type="button" name="button2" id="button2" value="删除" class="anniu" width="73px"
                                                height="23px" onclick="del();" />
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </div>
    <!--弹出公告详细信息-->
    <div id="plastudentinfo" class="easyui-dialog tcc_M">
        <ul>
            <li>公告标题：
                <input type="text" id="txttilt" style="width: 400px;" class="easyui-validatebox"
                    data-options="required:true" maxlength="60" /></li><li>&nbsp;</li>
            <li>接收对象：
                <select id="selrec" class="easyui-combobox" data-options="required:true,editable:false">
                    <option value="0">全部</option>
                    <option value="1">学校</option>
                    <option value="2">家长</option>
                    <option value="3">被放弃学生</option>
                </select></li><li>&nbsp;</li>
            <li>是否显示：
                <select id="selsta" class="easyui-combobox" data-options="required:true,editable:false">
                    <option value="0">显示</option>
                    <option value="1">不显示</option>
                </select></li><li>&nbsp;</li>
            <li>公告类容：
                <textarea id="txtcount" style="width: 400px;" rows="5"></textarea></li><li>&nbsp;</li>
            <li style="width: 73px; margin: 0px auto">
                <input type="button" name="button2" id="button5" value="修改" class="anniu" width="73px"
                    height="23px" onclick="updatenoice();" /></li>
        </ul>
    </div>
</asp:Content>
